package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 添加菜品或套餐到购物车
     * @param shoppingCart
     */
    @Insert("insert into sky_take_out.shopping_cart values (null,#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void add(ShoppingCart shoppingCart);

    /**
     * 查询购物车
     * @param shoppingCart
     * @return
     */
    //@Select("select * from sky_take_out.shopping_cart where user_id=#{userId}")
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 根据用户id更新数量
     * @param shoppingCart
     */
    @Update("update sky_take_out.shopping_cart set number=#{number} where dish_id=#{dishId} or setmeal_id=#{setmealId}")
    void update(ShoppingCart shoppingCart);

    /**
     * 根据用户id清空购物车
     * @param shoppingCart
     */
    //@Delete("delete from sky_take_out.shopping_cart where user_id=#{userId}")
    void clean(ShoppingCart shoppingCart);

    /**
     * 根据id删除购物车
     * @param userId
     */
    @Delete("delete from sky_take_out.shopping_cart where user_id=#{userId}")
    void deleteById(Long userId);




}
